package Work0608_2;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Scanner;

public class Receive {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int ch;
		try {
			Socket s = new Socket("192.168.1.134", 8577);
			System.out.println("输入文件名:");
			String file = input.next();
			File a = new File("D:\\" + file);// 创下载的文件目录
			InputStream in = s.getInputStream();// 下载
			OutputStream out = s.getOutputStream();// 上传
			PrintWriter o = new PrintWriter(out);// 将上传信息转化为字符流
			FileOutputStream fout = new FileOutputStream(a);// 字节写入a中
			o.println(file);// 上传要下载的文件名

			while (in.read() != -1) {
				fout.write(in.read());
			}

			fout.flush();
			fout.close();

			System.out.println("下载完成");

			s.close();
		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
